package com.xl.qa.controller;

import com.xl.basic.annotation.LogIgnored;
import com.xl.basic.annotation.RoleIgnored;
import com.xl.basic.annotation.RoleValidated;
import com.xl.basic.entity.Result;
import com.xl.basic.entity.UserInfo;
import com.xl.qa.entity.param.AddIndexBannerParam;
import com.xl.qa.entity.param.QueryIndexBannerParam;
import com.xl.qa.entity.param.UpdIndexBannerParam;
import com.xl.basic.utils.LoginUtils;
import com.xl.dao.domain.XlIndexBanner;
import com.xl.qa.service.IndexBannerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 钟勇
 * Create in 2024/2/4 15:29
 */
@Tag(name = "首页广告")
@RestController
@RequestMapping("/api/IndexBanner")
@RequiredArgsConstructor
@RoleValidated
public class IndexBannerController {
    private final IndexBannerService bannerService;

    @Operation(summary = "新增首页广告")
    @PostMapping(value = "/addIndexBanner")
    Result<Integer> addIndexBanner(@Validated AddIndexBannerParam param) {
        Result<UserInfo> userInfoRes = LoginUtils.getUserInfo();
        return bannerService.addIndexBanner(param, userInfoRes.getResult());
    }

    @Operation(summary = "编辑首页广告")
    @PostMapping(value = "/updIndexBanner")
    Result<Object> updIndexBanner(@Validated UpdIndexBannerParam param) {
        Result<UserInfo> userInfoRes = LoginUtils.getUserInfo();
        return bannerService.updIndexBanner(param, userInfoRes.getResult());
    }

    @Operation(summary = "删除首页广告")
    @PostMapping(value = "/delIndexBanner")
    Result<Object> delIndexBanner(@NotNull(message = "广告ID不能为空") Integer bannerId) {
        Result<UserInfo> userInfoRes = LoginUtils.getUserInfo();
        return bannerService.delIndexBanner(bannerId, userInfoRes.getResult());
    }

    @Operation(summary = "获取首页广告明细")
    @PostMapping(value = "/getIndexBannerDetails")
    Result<XlIndexBanner> getIndexBannerDetails(@NotNull(message = "广告ID不能为空") Integer bannerId) {
        return bannerService.getIndexBannerDetails(bannerId);
    }

    @Operation(summary = "查询首页广告")
    @PostMapping(value = "/queryIndexBannerList")
    @RoleIgnored
    @LogIgnored
    Result<List<XlIndexBanner>> queryIndexBannerList(@Validated QueryIndexBannerParam param) {
        return bannerService.queryIndexBannerList(param);
    }
}
